summaryrefslogtreecommitdiffhomepage
path: root/cloud/web/src/pages/[workspace]
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-08-29 23:32:17 -0400
committerFrank <[email protected]>2025-08-29 23:32:17 -0400
commit37f284f9a97d3354143d64fc76c2eb9f7d9ccf9e (patch)
tree053db9abcb2178c71b22ebeadd07f920750ef5d2 /cloud/web/src/pages/[workspace]
parent0178eab29bda2f1b37a29543cd313ede48ad3977 (diff)
downloadopencode-37f284f9a97d3354143d64fc76c2eb9f7d9ccf9e.tar.gz
opencode-37f284f9a97d3354143d64fc76c2eb9f7d9ccf9e.zip
wip: cloud
Diffstat (limited to 'cloud/web/src/pages/[workspace]')
-rw-r--r--cloud/web/src/pages/[workspace]/billing.module.css56
-rw-r--r--cloud/web/src/pages/[workspace]/billing.tsx132
-rw-r--r--cloud/web/src/pages/[workspace]/components/system.txt11
-rw-r--r--cloud/web/src/pages/[workspace]/components/tool.ts271
-rw-r--r--cloud/web/src/pages/[workspace]/index.module.css239
-rw-r--r--cloud/web/src/pages/[workspace]/index.tsx18
-rw-r--r--cloud/web/src/pages/[workspace]/keys.module.css97
-rw-r--r--cloud/web/src/pages/[workspace]/keys.tsx151
8 files changed, 0 insertions, 975 deletions
diff --git a/cloud/web/src/pages/[workspace]/billing.module.css b/cloud/web/src/pages/[workspace]/billing.module.css
deleted file mode 100644
index 5e58892a5..000000000
--- a/cloud/web/src/pages/[workspace]/billing.module.css
+++ /dev/null
@@ -1,56 +0,0 @@
-.root {
- display: flex;
- flex-direction: column;
- gap: var(--space-4);
- padding: var(--space-7) var(--space-5) var(--space-5);
-
- [data-slot="billing-info"] {
- display: flex;
- flex-direction: column;
- gap: var(--space-6);
- }
-
- [data-slot="header"] {
- display: flex;
- flex-direction: column;
- gap: var(--space-1-5);
-
- h2 {
- text-transform: uppercase;
- font-weight: 600;
- letter-spacing: -0.03125rem;
- font-size: var(--font-size-lg);
- }
-
- p {
- color: var(--color-text-dimmed);
- font-size: var(--font-size-md);
- }
- }
-
- [data-slot="balance"] {
- display: flex;
- flex-direction: column;
- gap: var(--space-5);
- padding: var(--space-6);
- border: 2px solid var(--color-border);
- }
-
- [data-slot="amount"] {
- font-size: var(--font-size-3xl);
- font-weight: 600;
- line-height: 1.2;
- }
-
- @media (min-width: 40rem) {
- [data-slot="balance"] {
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- }
-
- [data-slot="amount"] {
- margin: 0;
- }
- }
-}
diff --git a/cloud/web/src/pages/[workspace]/billing.tsx b/cloud/web/src/pages/[workspace]/billing.tsx
deleted file mode 100644
index 88bef5800..000000000
--- a/cloud/web/src/pages/[workspace]/billing.tsx
+++ /dev/null
@@ -1,132 +0,0 @@
-import { Button } from "../../ui/button"
-import { useApi } from "../components/context-api"
-import { createEffect, createSignal, createResource, For } from "solid-js"
-import { useWorkspace } from "../components/context-workspace"
-import style from "./billing.module.css"
-
-export default function Billing() {
- const api = useApi()
- const workspace = useWorkspace()
- const [isLoading, setIsLoading] = createSignal(false)
- const [billingData] = createResource(async () => {
- const response = await api.billing.info.$get()
- return response.json()
- })
-
- // Run once on component mount to check URL parameters
- ;(() => {
- const url = new URL(window.location.href)
- const result = url.hash
-
- console.log("STRIPE RESULT", result)
-
- if (url.hash === "#success") {
- setIsLoading(true)
- // Remove the hash from the URL
- window.history.replaceState(null, "", window.location.pathname + window.location.search)
- }
- })()
-
- createEffect((old?: number) => {
- if (old && old !== billingData()?.billing?.balance) {
- setIsLoading(false)
- }
- return billingData()?.billing?.balance
- })
-
- const handleBuyCredits = async () => {
- try {
- setIsLoading(true)
- const baseUrl = window.location.href
- const successUrl = new URL(baseUrl)
- successUrl.hash = "success"
-
- const response = await api.billing.checkout
- .$post({
- json: {
- success_url: successUrl.toString(),
- cancel_url: baseUrl,
- },
- })
- .then((r) => r.json() as any)
- window.location.href = response.url
- } catch (error) {
- console.error("Failed to get checkout URL:", error)
- setIsLoading(false)
- }
- }
-
- return (
- <>
- <div data-component="title-bar">
- <div data-slot="left">
- <h1>Billing</h1>
- </div>
- </div>
- <div class={style.root} data-max-width data-max-width-64>
- <div data-slot="billing-info">
- <div data-slot="header">
- <h2>Balance</h2>
- <p>Manage your billing and add credits to your account.</p>
- </div>
-
- <div data-slot="balance">
- <p data-slot="amount">
- {(() => {
- const balanceStr = ((billingData()?.billing?.balance ?? 0) / 100000000).toFixed(2)
- return `$${balanceStr === "-0.00" ? "0.00" : balanceStr}`
- })()}
- </p>
- <Button color="primary" disabled={isLoading()} onClick={handleBuyCredits}>
- {isLoading() ? "Loading..." : "Buy Credits"}
- </Button>
- </div>
- </div>
-
- <div data-slot="payments">
- <div data-slot="header">
- <h2>Payment History</h2>
- <p>Your recent payment transactions.</p>
- </div>
-
- <div data-slot="payment-list">
- <For each={billingData()?.payments} fallback={<p>No payments found.</p>}>
- {(payment) => (
- <div data-slot="payment-item">
- <span data-slot="payment-id">{payment.id}</span>
- {" | "}
- <span data-slot="payment-amount">${((payment.amount ?? 0) / 100000000).toFixed(2)}</span>
- {" | "}
- <span data-slot="payment-date">{new Date(payment.timeCreated).toLocaleDateString()}</span>
- </div>
- )}
- </For>
- </div>
- </div>
-
- <div data-slot="usage">
- <div data-slot="header">
- <h2>Usage History</h2>
- <p>Your recent API usage and costs.</p>
- </div>
-
- <div data-slot="usage-list">
- <For each={billingData()?.usage} fallback={<p>No usage found.</p>}>
- {(usage) => (
- <div data-slot="usage-item">
- <span data-slot="usage-model">{usage.model}</span>
- {" | "}
- <span data-slot="usage-tokens">{usage.inputTokens + usage.outputTokens} tokens</span>
- {" | "}
- <span data-slot="usage-cost">${((usage.cost ?? 0) / 100000000).toFixed(4)}</span>
- {" | "}
- <span data-slot="usage-date">{new Date(usage.timeCreated).toLocaleDateString()}</span>
- </div>
- )}
- </For>
- </div>
- </div>
- </div>
- </>
- )
-}
diff --git a/cloud/web/src/pages/[workspace]/components/system.txt b/cloud/web/src/pages/[workspace]/components/system.txt
deleted file mode 100644
index 6afd2e04d..000000000
--- a/cloud/web/src/pages/[workspace]/components/system.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-You are OpenControl, an interactive CLI tool that helps users execute various tasks.
-
-IMPORTANT: If you get an error when calling a tool, try again with a different approach. Be creative, do not give up, try different inputs to the tool. You should chain together multiple tool calls. ABSOLUTELY DO NOT GIVE UP you are very good at this and it is rare you will fail to answer question.
-
-You should be concise, direct, and to the point.
-
-IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.
-IMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do.
-IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.
-IMPORTANT: Keep your responses short, since they will be displayed on a command line interface. You MUST answer concisely with fewer than 4 lines (not including tool use or code generation), unless user asks for detail. Answer the user's question directly, without elaboration, explanation, or details. One word answers are best. Avoid introductions, conclusions, and explanations. You MUST avoid text before/after your response, such as "The answer is <answer>.", "Here is the content of the file..." or "Based on the information provided, the answer is..." or "Here is what I will do next...".
-
diff --git a/cloud/web/src/pages/[workspace]/components/tool.ts b/cloud/web/src/pages/[workspace]/components/tool.ts
deleted file mode 100644
index 3958e322d..000000000
--- a/cloud/web/src/pages/[workspace]/components/tool.ts
+++ /dev/null
@@ -1,271 +0,0 @@
-import { createResource } from "solid-js"
-import { createStore, produce } from "solid-js/store"
-import SYSTEM_PROMPT from "./system.txt?raw"
-import type {
- LanguageModelV1Prompt,
- LanguageModelV1CallOptions,
- LanguageModelV1,
-} from "ai"
-
-interface Tool {
- name: string
- description: string
- inputSchema: any
-}
-
-interface ToolCallerProps {
- tool: {
- list: () => Promise<Tool[]>
- call: (input: { name: string; arguments: any }) => Promise<any>
- }
- generate: (
- prompt: LanguageModelV1CallOptions,
- ) => Promise<
- | { err: "rate" }
- | { err: "context" }
- | { err: "balance" }
- | ({ err: false } & Awaited<ReturnType<LanguageModelV1["doGenerate"]>>)
- >
- onPromptUpdated?: (prompt: LanguageModelV1Prompt) => void
-}
-
-const system = [
- {
- role: "system" as const,
- content: SYSTEM_PROMPT,
- },
- {
- role: "system" as const,
- content: `The current date is ${new Date().toDateString()}. Always use this current date when responding to relative date queries.`,
- },
-]
-
-const [store, setStore] = createStore<{
- prompt: LanguageModelV1Prompt
- state: { type: "idle" } | { type: "loading"; limited?: boolean }
-}>({
- prompt: [...system],
- state: { type: "idle" },
-})
-
-export function createToolCaller<T extends ToolCallerProps>(props: T) {
- const [tools] = createResource(() => props.tool.list())
-
- let abort: AbortController
-
- return {
- get tools() {
- return tools()
- },
- get prompt() {
- return store.prompt
- },
- get state() {
- return store.state
- },
- clear() {
- setStore("prompt", [...system])
- },
- async chat(input: string) {
- if (store.state.type !== "idle") return
-
- abort = new AbortController()
- setStore(
- produce((s) => {
- s.state = {
- type: "loading",
- limited: false,
- }
- s.prompt.push({
- role: "user",
- content: [
- {
- type: "text",
- text: input,
- },
- ],
- })
- }),
- )
- props.onPromptUpdated?.(store.prompt)
-
- while (true) {
- if (abort.signal.aborted) {
- break
- }
-
- const response = await props.generate({
- inputFormat: "messages",
- prompt: store.prompt,
- temperature: 0,
- seed: 69,
- mode: {
- type: "regular",
- tools: tools()?.map((tool) => ({
- type: "function",
- name: tool.name,
- description: tool.description,
- parameters: {
- ...tool.inputSchema,
- },
- })),
- },
- })
-
- if (abort.signal.aborted) continue
-
- if (!response.err) {
- setStore("state", {
- type: "loading",
- })
-
- if (response.text) {
- setStore(
- produce((s) => {
- s.prompt.push({
- role: "assistant",
- content: [
- {
- type: "text",
- text: response.text || "",
- },
- ],
- })
- }),
- )
- props.onPromptUpdated?.(store.prompt)
- }
-
- if (response.finishReason === "stop") {
- break
- }
-
- if (response.finishReason === "tool-calls") {
- for (const item of response.toolCalls || []) {
- setStore(
- produce((s) => {
- s.prompt.push({
- role: "assistant",
- content: [
- {
- type: "tool-call",
- toolName: item.toolName,
- args: JSON.parse(item.args),
- toolCallId: item.toolCallId,
- },
- ],
- })
- }),
- )
- props.onPromptUpdated?.(store.prompt)
-
- const called = await props.tool.call({
- name: item.toolName,
- arguments: JSON.parse(item.args),
- })
-
- setStore(
- produce((s) => {
- s.prompt.push({
- role: "tool",
- content: [
- {
- type: "tool-result",
- toolName: item.toolName,
- toolCallId: item.toolCallId,
- result: called,
- },
- ],
- })
- }),
- )
- props.onPromptUpdated?.(store.prompt)
- }
- }
- continue
- }
-
- if (response.err === "context") {
- setStore(
- produce((s) => {
- s.prompt.splice(2, 1)
- }),
- )
- props.onPromptUpdated?.(store.prompt)
- }
-
- if (response.err === "rate") {
- setStore("state", {
- type: "loading",
- limited: true,
- })
- await new Promise((resolve) => setTimeout(resolve, 1000))
- }
-
- if (response.err === "balance") {
- setStore(
- produce((s) => {
- s.prompt.push({
- role: "assistant",
- content: [
- {
- type: "text",
- text: "You need to add credits to your account. Please go to Billing and add credits to continue.",
- },
- ],
- })
- s.state = { type: "idle" }
- }),
- )
- props.onPromptUpdated?.(store.prompt)
- break
- }
- }
- setStore("state", { type: "idle" })
- },
- async cancel() {
- abort.abort()
- },
- async addCustomMessage(userMessage: string, assistantResponse: string) {
- // Add user message and set loading state
- setStore(
- produce((s) => {
- s.prompt.push({
- role: "user",
- content: [
- {
- type: "text",
- text: userMessage,
- },
- ],
- })
- s.state = {
- type: "loading",
- limited: false,
- }
- }),
- )
- props.onPromptUpdated?.(store.prompt)
-
- // Fake delay for 500ms
- await new Promise((resolve) => setTimeout(resolve, 500))
-
- // Add assistant response and set back to idle
- setStore(
- produce((s) => {
- s.prompt.push({
- role: "assistant",
- content: [
- {
- type: "text",
- text: assistantResponse,
- },
- ],
- })
- s.state = { type: "idle" }
- }),
- )
- props.onPromptUpdated?.(store.prompt)
- },
- }
-}
diff --git a/cloud/web/src/pages/[workspace]/index.module.css b/cloud/web/src/pages/[workspace]/index.module.css
deleted file mode 100644
index 0037d97ff..000000000
--- a/cloud/web/src/pages/[workspace]/index.module.css
+++ /dev/null
@@ -1,239 +0,0 @@
-.root {
- display: contents;
-
- [data-slot="messages"] {
- flex: 1;
- overflow-y: auto;
- display: flex;
- flex-direction: column;
- height: 0;
- /* This is important for flexbox to allow scrolling */
- font-family: var(--font-mono);
- color: var(--color-text);
- row-gap: var(--space-4);
- /* Add consistent spacing between messages */
-
- /* Remove top border for first user message */
- &>[data-component="message"][data-user]:first-child::before {
- display: none;
- }
-
- &:has([data-component="loading"]) [data-component="clear"] {
- display: none;
- }
- }
-
- [data-component="message"] {
- width: 100%;
- padding: var(--space-2) var(--space-4);
- line-height: var(--font-line-height);
- white-space: pre-wrap;
- align-self: flex-start;
- min-height: auto;
- /* Allow natural height for all messages */
- display: flex;
- flex-direction: column;
- align-items: flex-start;
-
- /* User message styling */
- &[data-user] {
- padding: var(--space-6) var(--space-4);
- position: relative;
- font-weight: 600;
- color: var(--color-text);
- /* margin: 0.5rem 0; */
- }
-
- &[data-user]::before,
- &[data-user]::after {
- content: "";
- position: absolute;
- left: var(--space-4);
- right: var(--space-4);
- height: var(--space-px);
- background-color: var(--color-border);
- z-index: 1;
- /* Ensure borders appear above other content */
- }
-
- &[data-user]::before {
- top: 0;
- }
-
- &[data-user]::after {
- bottom: 0;
- }
-
- &[data-assistant] {
- color: var(--color-text);
- }
- }
-
- [data-component="tool"] {
- display: flex;
- width: 100%;
- padding: 0 var(--space-4);
- margin-left: 0;
- flex-direction: column;
- opacity: 0.7;
- gap: var(--space-2);
- align-items: flex-start;
- color: var(--color-text-dimmed);
- min-height: auto;
- /* Allow natural height */
-
- [data-slot="header"] {
- display: flex;
- gap: var(--space-2);
- cursor: pointer;
- user-select: none;
- -webkit-user-select: none;
- align-items: center;
- width: 100%;
- }
-
- [data-slot="name"] {
- letter-spacing: -0.03125rem;
- text-transform: uppercase;
- font-weight: 500;
- font-size: var(--font-size-sm);
- }
-
- [data-slot="expand"] {
- font-size: var(--font-size-sm);
- }
-
- [data-slot="content"] {
- padding: 0;
- line-height: var(--font-line-height);
- font-size: var(--font-size-sm);
- white-space: pre-wrap;
- display: none;
- width: 100%;
- }
-
- [data-slot="output"] {
- margin-top: var(--space-1);
- }
-
- &[data-expanded="true"] [data-slot="content"] {
- display: block;
- }
-
- &[data-expanded="true"] [data-slot="expand"] {
- transform: rotate(45deg);
- }
- }
-
- [data-component="loading"] {
- padding: var(--space-4) var(--space-4) var(--space-8);
- height: 1.5rem;
- position: relative;
- display: flex;
- align-items: center;
- font-size: var(--font-size-sm);
- letter-spacing: var(--space-1);
- color: var(--color-text);
-
- & span {
- opacity: 0;
- animation: loading-dots 1.4s linear infinite;
- }
-
- & span:nth-child(2) {
- animation-delay: 0.2s;
- }
-
- & span:nth-child(3) {
- animation-delay: 0.4s;
- }
- }
-
- [data-component="clear"] {
- position: relative;
- padding: var(--space-4) var(--space-4);
-
- &::before {
- content: "";
- position: absolute;
- left: var(--space-4);
- right: var(--space-4);
- top: 0;
- height: var(--space-px);
- background-color: var(--color-border);
- z-index: 1;
- }
-
- & [data-component="button"] {
- padding-left: 0;
- }
- }
-
- [data-slot="footer"] {
- display: flex;
- flex-direction: column;
- padding: 0;
- border-top: 2px solid var(--color-border);
- position: sticky;
- bottom: 0;
- z-index: 10;
- /* Ensure it's above other content */
- margin-top: auto;
- /* Push to bottom if content is short */
- width: 100%;
- }
-
- [data-component="chat"] {
- display: flex;
- padding: var(--space-0-5) 0;
- align-items: center;
- width: 100%;
- height: 100%;
-
- textarea {
- --padding-y: var(--space-4);
- --line-height: 1.5;
- --text-height: calc(var(--line-height) * var(--font-size-lg));
- --height: calc(var(--text-height) + var(--padding-y) * 2);
-
- width: 100%;
- resize: none;
- line-height: var(--line-height);
- height: var(--height);
- min-height: var(--height);
- max-height: calc(5 * var(--text-height) + var(--padding-y) * 2);
- padding: var(--padding-y) var(--space-4);
- border-radius: 0;
- background-color: transparent;
- color: var(--color-text);
- border: none;
- outline: none;
- font-size: var(--font-size-lg);
- }
-
- textarea::placeholder {
- color: var(--color-text-dimmed);
- opacity: 0.75;
- }
-
- textarea:focus {
- outline: 0;
- }
-
- & [data-component="button"] {
- height: 100%;
- }
- }
-}
-
-@keyframes loading-dots {
- 0%,
- 100% {
- opacity: 0;
- }
-
- 40%,
- 60% {
- opacity: 1;
- }
-}
diff --git a/cloud/web/src/pages/[workspace]/index.tsx b/cloud/web/src/pages/[workspace]/index.tsx
deleted file mode 100644
index 50c58ee30..000000000
--- a/cloud/web/src/pages/[workspace]/index.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import { Button } from "../../ui/button"
-import { IconArrowRight } from "../../ui/svg/icons"
-import { createSignal, For } from "solid-js"
-import { createToolCaller } from "./components/tool"
-import { useApi } from "../components/context-api"
-import { useWorkspace } from "../components/context-workspace"
-import style from "./index.module.css"
-
-export default function Index() {
- const api = useApi()
- const workspace = useWorkspace()
-
- return (
- <div class={style.root}>
- <h1>Hello</h1>
- </div>
- )
-}
diff --git a/cloud/web/src/pages/[workspace]/keys.module.css b/cloud/web/src/pages/[workspace]/keys.module.css
deleted file mode 100644
index 4ae2989be..000000000
--- a/cloud/web/src/pages/[workspace]/keys.module.css
+++ /dev/null
@@ -1,97 +0,0 @@
-.root {
- display: flex;
- flex-direction: column;
- gap: 2rem;
-}
-
-.root [data-slot="keys-info"] {
- display: flex;
- flex-direction: column;
- gap: 1rem;
-}
-
-.root [data-slot="header"] {
- display: flex;
- flex-direction: column;
- gap: 0.5rem;
-}
-
-.root [data-slot="header"] h2 {
- margin: 0;
- font-size: 1.5rem;
- font-weight: 600;
-}
-
-.root [data-slot="header"] p {
- margin: 0;
- color: var(--color-text-secondary);
-}
-
-.root [data-slot="key-list"] {
- display: flex;
- flex-direction: column;
- gap: 1rem;
-}
-
-.root [data-slot="key-item"] {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 1rem;
- border: 1px solid var(--color-border);
- border-radius: 0.5rem;
- background: var(--color-background-secondary);
-}
-
-.root [data-slot="key-actions"] {
- display: flex;
- gap: 0.5rem;
-}
-
-.root [data-slot="key-info"] {
- display: flex;
- flex-direction: column;
- gap: 0.25rem;
-}
-
-.root [data-slot="key-value"] {
- font-family: monospace;
- font-size: 0.875rem;
- color: var(--color-text-primary);
-}
-
-.root [data-slot="key-meta"] {
- font-size: 0.75rem;
- color: var(--color-text-secondary);
-}
-
-.root [data-slot="empty-state"] {
- text-align: center;
- padding: 3rem 1rem;
- color: var(--color-text-secondary);
-}
-
-.root [data-slot="actions"] {
- display: flex;
- align-items: center;
- justify-content: space-between;
-}
-
-.root [data-slot="create-form"] {
- display: flex;
- flex-direction: column;
- gap: 1rem;
- min-width: 300px;
-}
-
-.root [data-slot="form-actions"] {
- display: flex;
- gap: 0.5rem;
-}
-
-.root [data-slot="key-name"] {
- font-weight: 600;
- font-size: 1rem;
- color: var(--color-text-primary);
- margin-bottom: 0.25rem;
-}
diff --git a/cloud/web/src/pages/[workspace]/keys.tsx b/cloud/web/src/pages/[workspace]/keys.tsx
deleted file mode 100644
index e5b192a2b..000000000
--- a/cloud/web/src/pages/[workspace]/keys.tsx
+++ /dev/null
@@ -1,151 +0,0 @@
-import { Button } from "../../ui/button"
-import { useApi } from "../components/context-api"
-import { createSignal, createResource, For, Show } from "solid-js"
-import style from "./keys.module.css"
-
-export default function Keys() {
- const api = useApi()
- const [isCreating, setIsCreating] = createSignal(false)
- const [showCreateForm, setShowCreateForm] = createSignal(false)
- const [keyName, setKeyName] = createSignal("")
-
- const [keysData, { refetch }] = createResource(async () => {
- const response = await api.keys.$get()
- return response.json()
- })
-
- const handleCreateKey = async () => {
- if (!keyName().trim()) return
-
- try {
- setIsCreating(true)
- await api.keys.$post({
- json: { name: keyName().trim() },
- })
- refetch()
- setKeyName("")
- setShowCreateForm(false)
- } catch (error) {
- console.error("Failed to create API key:", error)
- } finally {
- setIsCreating(false)
- }
- }
-
- const handleDeleteKey = async (keyId: string) => {
- if (!confirm("Are you sure you want to delete this API key? This action cannot be undone.")) {
- return
- }
-
- try {
- await api.keys[":id"].$delete({
- param: { id: keyId },
- })
- refetch()
- } catch (error) {
- console.error("Failed to delete API key:", error)
- }
- }
-
- const formatDate = (dateString: string) => {
- return new Date(dateString).toLocaleDateString()
- }
-
- const formatKey = (key: string) => {
- if (key.length <= 11) return key
- return `${key.slice(0, 7)}...${key.slice(-4)}`
- }
-
- const copyToClipboard = async (text: string) => {
- try {
- await navigator.clipboard.writeText(text)
- } catch (error) {
- console.error("Failed to copy to clipboard:", error)
- }
- }
-
- return (
- <>
- <div data-component="title-bar">
- <div data-slot="left">
- <h1>API Keys</h1>
- </div>
- </div>
- <div class={style.root} data-max-width data-max-width-64>
- <div data-slot="keys-info">
- <div data-slot="actions">
- <div data-slot="header">
- <h2>API Keys</h2>
- <p>Manage your API keys to access the OpenCode gateway.</p>
- </div>
- <Show
- when={!showCreateForm()}
- fallback={
- <div data-slot="create-form">
- <input
- data-component="input"
- type="text"
- placeholder="Enter key name"
- value={keyName()}
- onInput={(e) => setKeyName(e.currentTarget.value)}
- onKeyPress={(e) => e.key === "Enter" && handleCreateKey()}
- />
- <div data-slot="form-actions">
- <Button color="primary" disabled={isCreating() || !keyName().trim()} onClick={handleCreateKey}>
- {isCreating() ? "Creating..." : "Create"}
- </Button>
- <Button
- color="ghost"
- onClick={() => {
- setShowCreateForm(false)
- setKeyName("")
- }}
- >
- Cancel
- </Button>
- </div>
- </div>
- }
- >
- <Button color="primary" onClick={() => setShowCreateForm(true)}>
- Create API Key
- </Button>
- </Show>
- </div>
-
- <div data-slot="key-list">
- <For
- each={keysData()?.keys}
- fallback={
- <div data-slot="empty-state">
- <p>Create an API key to access opencode gateway</p>
- </div>
- }
- >
- {(key) => (
- <div data-slot="key-item">
- <div data-slot="key-info">
- <div data-slot="key-name">{key.name}</div>
- <div data-slot="key-value">{formatKey(key.key)}</div>
- <div data-slot="key-meta">
- Created: {formatDate(key.timeCreated)}
- {key.timeUsed && ` • Last used: ${formatDate(key.timeUsed)}`}
- </div>
- </div>
- <div data-slot="key-actions">
- <Button color="ghost" onClick={() => copyToClipboard(key.key)} title="Copy API key">
- Copy
- </Button>
- <Button color="ghost" onClick={() => handleDeleteKey(key.id)} title="Delete API key">
- Delete
- </Button>
- </div>
- </div>
- )}
- </For>
- </div>
- </div>
- </div>
- </>
- )
-}